/*
 * Copyright 2005-2013 shopxx.net. All rights reserved.
 * Support: http://www.shopxx.net
 * License: http://www.shopxx.net/license
 */
package com.xiaorong.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiaorong.Filter;
import com.xiaorong.Filter.Operator;
import com.xiaorong.Pageable;
import com.xiaorong.dao.LogDao;

@Controller
@RequestMapping("/log")
public class LogController extends BaseController {

	@Resource
	private LogDao logDao;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(Pageable pageable, HttpServletRequest request) {
		String operation = request.getParameter("operation");
		if(StringUtils.isNotBlank(operation)){
			List<Filter> filters = new ArrayList<Filter>();
			filters.add(new Filter("operation", Operator.eq, operation.trim()));
			pageable.setFilters(filters);
			request.setAttribute("operation", operation);
		}
		request.setAttribute("page", logDao.findPage(pageable));
		return "/log/list";
	}

	@RequestMapping(value = "/view", method = RequestMethod.GET)
	public String view(Long id,HttpServletRequest request) {
		request.setAttribute("log", logDao.find(id));
		return "/log/view";
	}

	@RequestMapping(value = "/delete", method = RequestMethod.GET)
	public @ResponseBody
	boolean delete(Long[] ids) {
		if (ids != null) {
			for (Long id : ids) {
				logDao.remove(id);
			}
		}
		return true;
	}
}